package xyz.eden.cloud.common.web.enums;

import lombok.AllArgsConstructor;
import xyz.eden.cloud.common.core.enums.ICodeMsgEnum;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

@AllArgsConstructor
public enum StatusEnum implements ICodeMsgEnum<Integer> {

    /**
     * 禁用
     */
    DISABLE(0, "禁用"),
    /**
     * 启用
     */
    ENABLE(1, "启用");

    private final Integer code;
    private final String msg;

    private static final Map<Integer, StatusEnum> _map;

    static {
        _map = Arrays.stream(Optional.of(values()).orElse(new StatusEnum[]{}))
                .collect(Collectors.toMap(StatusEnum::getCode, Function.identity(), (o1, o2) -> o2));
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String getMsg() {
        return this.msg;
    }

    public static StatusEnum of(Integer code) {
        return _map.get(code);
    }
}
